<template>
  <!-- 模板不变，仅统一性别枚举显示 -->
  <div class="reception-elder">
    <div class="header">
      <h2>老人信息</h2>
      <p>查看养老中心所有老人的基本信息</p>
    </div>
    <div class="filter-container">
      <el-form :inline="true" :model="queryParams" class="demo-form-inline">
        <!-- 筛选项不变 -->
      </el-form>
    </div>
    <div class="table-container">
      <el-table
          :data="elderList"
          v-loading="loading"
          border
          style="width: 100%"
      >
        <el-table-column prop="gender" label="性别" width="80" align="center">
          <template #default="{ row }">
            <el-tag :type="row.gender === 1 ? 'primary' : 'success'">
              {{ row.gender === 1 ? '男' : '女' }} <!-- 统一枚举 -->
            </el-tag>
          </template>
        </el-table-column>
        <!-- 其他列不变 -->
      </el-table>
      <div class="pagination-container">
        <!-- 分页不变 -->
      </div>
    </div>
    <!-- 详情对话框不变 -->
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { elderApi } from '@/api/elder.js'

// 响应式数据不变
const loading = ref(false)
const elderList = ref([])
const total = ref(0)
const detailVisible = ref(false)
const currentElder = ref(null)
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  name: '',
  bedId: '',
  healthStatus: ''
})

// 修复：前台查所有老人（无需过滤，与管理员一致）
const loadData = async () => {
  try {
    loading.value = true
    const response = await elderApi.getElders(queryParams) // 前台无需传caregiverId/familyId
    if (response.code === 200) {
      elderList.value = response.data.records || []
      total.value = response.data.total || 0
    } else {
      ElMessage.error(response.msg || '获取数据失败')
    }
  } catch (error) {
    console.error('加载数据失败:', error)
    ElMessage.error('加载数据失败')
  } finally {
    loading.value = false
  }
}

// 其他逻辑不变
const handleQuery = () => { queryParams.pageNum = 1; loadData() }
const resetQuery = () => {
  Object.assign(queryParams, { pageNum: 1, pageSize: 10, name: '', bedId: '', healthStatus: '' })
  loadData()
}
const handleSizeChange = (val) => { queryParams.pageSize = val; queryParams.pageNum = 1; loadData() }
const handleCurrentChange = (val) => { queryParams.pageNum = val; loadData() }
const handleView = (row) => { currentElder.value = row; detailVisible.value = true }
const handleCloseDetail = () => { detailVisible.value = false; currentElder.value = null }

onMounted(() => {
  loadData()
})
</script>
<style scoped>
/* 样式不变 */
</style>